/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */
package space.model;

import javax.media.opengl.GL3bc;
import space.gl.RenderContext;

/**
 *
 * @author Pierre
 */
public class MeshVertexArray implements Drawable {

    boolean disposed = false;
    final int buffersIds[];
    final MeshVertexArrayDrawElement vades[];

    public MeshVertexArray(int[] buffersIds,
            MeshVertexArrayDrawElement[] vades) {

        this.buffersIds = buffersIds;
        this.vades = vades;
    }

    public void draw(RenderContext rc) {
        rc.applyAllUniforms();
        GL3bc gl = rc.gl();
        //Empty.drawBasis(gl);
        for (final MeshVertexArrayDrawElement vade : vades) {
            vade.draw(gl);
        }
    }

    public void dispose(GL3bc gl) {
        if (disposed == false) {
            disposed = true;
            gl.glDeleteBuffers(buffersIds.length, buffersIds, 0);
            for (MeshVertexArrayDrawElement vade : vades) {
                vade.dispose(gl);
            }
        }
    }

    public Drawable optimize(GL3bc gl) {
        /**
         * Nothing to do because this structure is allready optimized
         */
        return this;
    }
}
